package turtle.system.invest.evaluate;

import java.util.NoSuchElementException;

import org.osite.xml.XmlConstructor;
import org.osite.xml.XmlParam;

import turtle.system.invest.Environment;
import turtle.system.invest.IndexSeries;
import turtle.system.invest.rule.InvestRunnable;

public class TimestampSetter implements InvestRunnable {

    private final String seriesName;

    @XmlConstructor
    public TimestampSetter(@XmlParam("series") String seriesName) {
        this.seriesName = seriesName;
    }

    @Override
    public void run(Environment environment) {
        IndexSeries series = environment.get(seriesName, null);
        if (series == null) throw new NoSuchElementException(seriesName);
        environment.set(Simulate.START_TIMESTAMP, 0);
        environment.set(Simulate.END_TIMESTAMP, series.size());
    }
}
